#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
int a[N], n;
int Sum = 0;
int Color[N], Fail = 0;
inline int Solve(int x){
    Fail = 0;
    while(x){
        Color[++Fail] = x & 1;
        x >>= 1;
    }
    int ans = 0;
    for(register int i = 1; i <= n; i++){
        for(register int j = i - 1; j >= 1; j--){
            if(Color[i] == Color[j]){
                if(a[i] == a[j]) ans += a[i];
                break;
            }
        }
    }
    return ans;
}
namespace CSP{
    inline void Dijkstra(){
        int Max_num = -1, Step = 0;
        for(register int step = 0; step < (1 << n + 1); step++){
            int Result = Solve(step);
            if(Result > Max_num){
                Max_num = Result;
                Step = step;
            }
        }
        cout << Max_num << "\n";
        return ;
    }
}
namespace IOI{
    inline void spfa(){
        int Max_num = -1;
        int Range = (1 << n + 1);
        srand(time(0));
        for(register int i = 1; i <= n * 10; i++){
            int step = rand() % Range;
            int Result = Solve(step);
            if(Result > Max_num) Max_num = Result;
        }
        cout << Max_num << "\n";
        return ;
    }
}
signed main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    while(T--){
        cin >> n;
        for(register int i = 1; i <= n; i++) cin >> a[i];
        Sum = 0;
        for(register int i = 1; i <= n; i++) Sum += a[i];
        if(n <= 50) CSP::Dijkstra();
        else IOI::spfa();
    }
    return 0;
}
